//
//  HWXiHuanTableViewCell.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/9/9.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWXiHuanTableViewCell.h"

@interface HWXiHuanTableViewCell()
@property(strong,nonatomic) NSArray *dataArr;
@property(strong,nonatomic) NSMutableArray *icoMuArr;
@property(strong,nonatomic) NSMutableArray *labelArr;

@end

@implementation HWXiHuanTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
        
    }
    
    return  self;
    
}


- (void) setupUI {
    
    self.dataArr = @[@"勇者之路",@"魔兽",@"幻城",@" 战神"];
  //  self.icoImageArr = @[@"youxiangxiangqing",@"youxiangxiangqing",@"youxiangxiangqing",@"youxiangxiangqing"];
    CGFloat w =  (SCREEN_WIDTH- 58*CFLScaleValue*4-25*2)/3;
    self.icoMuArr = [[NSMutableArray alloc]init];
    self.labelArr = [[NSMutableArray alloc]init];
    for (int i = 0; i < self.dataArr.count; i++) {
       
        UIView *redview =  [[UIView alloc]initWithFrame:CGRectMake(i*58*CFLScaleValue+25+w*i, 3, 58*CFLScaleValue, 58*CFLScaleValue+21)];
        [self.contentView addSubview:redview];
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 58*CFLScaleValue, 58*CFLScaleValue)];
        imageView.image  = [UIImage imageNamed:@"youxiangxiangqing"];
        imageView.tag = i;
        imageView.userInteractionEnabled = YES;
        imageView.tag = i;
        
        imageView.layer.cornerRadius = 12;
        imageView.layer.masksToBounds = YES;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView:)];
        imageView.userInteractionEnabled = YES;
        
        [imageView addGestureRecognizer:tap];
        [redview addSubview:imageView];
        
        UILabel *texelabel = [[UILabel alloc]initWithFrame:CGRectMake(-10,  58*CFLScaleValue+8, 58*CFLScaleValue+20, 13)];
        texelabel.textAlignment = NSTextAlignmentCenter;
        texelabel.textColor = RGB(51, 51, 51);
        texelabel.text = self.dataArr[i];
        
      //  texelabel.backgroundColor = [UIColor redColor];
        texelabel.font = [UIFont systemFontOfSize:13];
        [redview addSubview:texelabel];
       
        [self.icoMuArr addObject:imageView];
        [self.labelArr addObject:texelabel];
        
        
    }
    
}

- (void)tapView:(UITapGestureRecognizer *)sende {
    
    DLog(@"dmoipjcw");
    NSInteger tag =   sende.view.tag ;
    HWGameDetailController *xiangqing = [[HWGameDetailController alloc]init];
    
    NSDictionary *dic = self.gameArr[tag];
    xiangqing.gameId = dic[@"id"];
    [[HWViewUtils getCurrentVC].navigationController  pushViewController:xiangqing animated:YES];
    
    
    
}

- (void)setGameArr:(NSArray *)gameArr {
    
      _gameArr = gameArr;
    
//      {
//          icon = "http://demo.94php.com/static/uploads/mobile/2019073113451095878.jpg";
//          id = 461;
//          name = "\U70ed\U8840\U795e\U5251\U5b98\U65b9\U7248";
//      }
    
    
    
    
    
    if (gameArr.count >  0 ) {
        
        
        for (int i = 0; i < gameArr.count; i++) {
            
            
            
             if (i > 3) {
                return;
           
             }
             NSDictionary *dic = gameArr[i];
             NSLog(@"猜你喜欢 %@",dic);
             
             NSString *urlSttr = [NSString stringWithFormat:@"%@",dic[@"icon"]];
             NSURL *url = [NSURL URLWithString:urlSttr];
             
             UIImageView *imgeView = self.icoMuArr[i];
             UILabel *label = self.labelArr[i];
             
             [imgeView sd_setImageWithURL:url];
             label.text = dic[@"name"];
            
             imgeView.hidden = NO;
             label.hidden = NO;
            
            
             
             
         }
         
        
        
        
        
    } else {
        
        
        
        for (int i = 0; i < 4; i++) {
//             NSDictionary *dic = gameArr[i];
//             NSLog(@"猜你喜欢 %@",dic);
//
//            NSString *urlSttr = [NSString stringWithFormat:@"%@",dic[@"icon"]];
//            NSURL *url = [NSURL URLWithString:urlSttr];
            UIImageView *imgeView = self.icoMuArr[i];
            UILabel *label = self.labelArr[i];
            imgeView.hidden = YES;
            label.hidden = YES;
            
           // [imgeView sd_setImageWithURL:url];
          //  label.text = dic[@"name"];
                    
                    
        }
        
        
        
    }
    
  
    
 
    
    
        
    
    
    
    
}

@end
